package com.lang.JsonConfig;

import com.alibaba.fastjson2.JSONFactory;
import com.alibaba.fastjson2.reader.ObjectReaderProvider;
import com.alibaba.fastjson2.writer.ObjectWriterProvider;

import java.time.Duration;

public class JSONConfig {

    public static void init() {
        initWriter();
        initReader();
    }

    private static void initWriter() {
        ObjectWriterProvider defaultObjectWriterProvider = JSONFactory.getDefaultObjectWriterProvider();
        defaultObjectWriterProvider.register(Duration.class, new DurationJsonSerializeUsing());
    }

    private static void initReader() {
        ObjectReaderProvider defaultObjectReaderProvider = JSONFactory.getDefaultObjectReaderProvider();
        defaultObjectReaderProvider.register(Duration.class, new DurationJsonDeserializeUsing());
    }
}
